package exception;

import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

public class FinallyDemo3 {
    public static void main(String[] args) {
    /*    FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("fos.dat");
            fos.write(1);
        } catch (IOException e) {
            System.out.println("出错了");
        } finally {
            try {
                if (fos!= null){
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }*/

        try (
                PrintWriter fw = new PrintWriter("bos.txt")
        ) {
            fw.println("123");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
